﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.IO;

class SearchForWordInFiles
{
    public const string SOURCE_DIR = @"D:\Downloads\Games\UNI\Telerik\NetEssentials\Elian Kurtenkov\1.12_InputOutput\CopyDirAndFiles\Test";
    public const string DESTIONATION_DIR = @"D:\Downloads\Games\UNI\Telerik\NetEssentials\Elian Kurtenkov\1.12_InputOutput\CopyDirAndFiles\Test_Succ";

    public static void CopyFromTo(string sourceDir, string destinationDir)
    {
        string[] allFiles = Directory.GetFiles(sourceDir);
        Directory.CreateDirectory(destinationDir);
        foreach (string file in allFiles)
        {
            string newFileName;
            string pattern = @"(.|\\)*\\";
            newFileName = Regex.Replace(file, pattern, destinationDir+@"\");
            File.Copy(file, newFileName, true);
        }
        string[] allSubDirs = Directory.GetDirectories(sourceDir);
        foreach (string dir in allSubDirs)
        {
            string[] folders = dir.Split('\\');
            string newSourceDir = sourceDir + "\\" + folders[folders.Length - 1];
            string newDestDir = destinationDir + "\\" + folders[folders.Length - 1];
            CopyFromTo(newSourceDir, newDestDir);
        }
    }

    static void Main(string[] args)
    {
        CopyFromTo(SOURCE_DIR, DESTIONATION_DIR);
    }
}
